import React, { useEffect, useState } from 'react';
import {
  Button,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Radio,
  Select,
  Switch,
  TreeSelect,
} from 'antd';
import * as asyncfn from '../store/crmSlice';
import { useAppDispatch, useAppSelector } from '../store/AppUse';

type SizeType = Parameters<typeof Form>[0]['size'];

const Myfrom: React.FC = (props) => {

    const obj = useAppSelector(state=>state.todos)
    const dispatch = useAppDispatch()

    const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
//   console.log('Success:', values);
if(props.title=='添加'){
    let obj = {
        ...values,
        "id":new Date().getTime()
    }
    dispatch(asyncfn.async_addshoplist(obj))
}else{
    let obj = {
        ...values,
        "id":props.itemobj.id
    }
    dispatch(asyncfn.async_editshoplist(obj))
}
props.onCancel()
};


  const [componentSize, setComponentSize] = useState<SizeType | 'default'>('default');

  const [form] = Form.useForm();

  const onFormLayoutChange = ({ size }: { size: SizeType }) => {
    setComponentSize(size);
  };

  useEffect(()=>{
    form.setFieldsValue(props.itemobj)
  },[])

  return (
    <Form form={form} onFinish={onFinish}>
      <Form.Item label="优惠券名称" name="couponName">
        <Input />
      </Form.Item>
      <Form.Item label="优惠券面值" name="couponFaceValue">
        <Input />
      </Form.Item>
      <Form.Item label="优惠券最低消费" name="couponMinimumConsumption">
        <Input />
      </Form.Item>
      <Form.Item label="优惠券有效期限" name="couponValidityPeriod">
        <Input />
      </Form.Item>
      <Form.Item label="排序" name="sort">
        <Input />
      </Form.Item>
      <Form.Item label="状态" name="status">
        <Input />
      </Form.Item>
      <Form.Item label="创建时间" name="createTime">
        <Input />
      </Form.Item>
      <Form.Item label="Button">
        <Button htmlType='submit'>完成</Button>
      </Form.Item>
    </Form>
  );
};

export default Myfrom;
